﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

using Oracle.ManagedDataAccess.Client;
using WFL.Data.Oracle;
using WFL.Windows;
using WFL.Windows.Forms;

namespace WFL.Demo.WinForm
{
    public partial class MainForm : TraditionalFormBase
    {
        public MainForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

        }

        private void _zoomOut_Click(object sender, EventArgs e)
        {
            Size = Size.Add(Size, new Size(100, 100));
        }

        private void _zoomIn_Click(object sender, EventArgs e)
        {
            Size = Size.Add(Size, new Size(-100, -100));
        }

        private void _rectCheck_Click(object sender, EventArgs e)
        {
            string text = "Bounds:{0}\nClientRectangle:{1}";
            text = string.Format(text, new object[]{
                Bounds.ToString()
                ,ClientRectangle.ToString()
                });
            MessageBox.Show(text);
        }

        private void _lowRect_Click(object sender, EventArgs e)
        {
            RECT rect, clientRect;
            int r1 = API.User32.GetWindowRect(Handle, out rect);
            int r2 = API.User32.GetClientRect(Handle, out clientRect);
            if (r1 == 0 || r2 == 0)
            {
                MessageBox.Show("失败：" + r1.ToString() + "," + r2.ToString());
            }
            else
            {
                string text = "Bounds:{0}\nClientRectangle:{1}";
                text = string.Format(text, new object[]{
                    new Rectangle(rect.Left,rect.Top,rect.Width,rect.Height).ToString()
                    ,new Rectangle(clientRect.Left,clientRect.Top,clientRect.Width,clientRect.Height).ToString()
                    });
                MessageBox.Show(text);
            }
            //RECT ncRect = new RECT() { Left = 0, Top = 0, Right = 0, Bottom = 0 };
            ////问题在这个api，返回的是标准的非客户区大小
            //int r3 = API.User32.AdjustWindowRectEx(ref ncRect, (uint)CreateParams.Style, 0, (uint)CreateParams.ExStyle);
            //if (r3 == 0)
            //{
            //    MessageBox.Show("获取非客户区大小失败");
            //}
            //else
            //{
            //    string text = "Size:{0},{1}";
            //    text = string.Format(text, new object[]{
            //        ncRect.Width.ToString()
            //        ,ncRect.Height.ToString()
            //        });
            //    MessageBox.Show(text);
            //}
        }

        private void _showStandard_Click(object sender, EventArgs e)
        {
            StandardForm standard = new StandardForm();
            standard.Size = new Size(600, 400);
            standard.Show();
        }

        private void _restoreBounds_Click(object sender, EventArgs e)
        {
            string text = "RestoreBounds:{0},{1}";
            text = string.Format(text, new object[]{
                    RestoreBounds.Width.ToString()
                    ,RestoreBounds.Height.ToString()
                    });
            MessageBox.Show(text);
        }

        private void _sizeWithApi_Click(object sender, EventArgs e)
        {
            uint flags = Header.Winuser.SWP_NOZORDER | Header.Winuser.SWP_NOMOVE | Header.Winuser.SWP_NOACTIVATE;
            int result = API.User32.SetWindowPos(Handle, IntPtr.Zero, Left, Top, 700, 500, flags);
            if (result == 0)
            {
                MessageBox.Show("设置大小失败。");
            }
        }

        private void _frameChange_Click(object sender, EventArgs e)
        {
            Padding nonclientArea = BorderThickness;
            nonclientArea.Top = 100;
            BorderThickness = nonclientArea;
        }

        private void _regionBounds_Click(object sender, EventArgs e)
        {
            if (Region != null)
            {
                MessageBox.Show(Region.GetBounds(this.CreateGraphics()).ToString());
            }
        }

        private void _screenBounds_Click(object sender, EventArgs e)
        {
            Rectangle screen = Screen.PrimaryScreen.Bounds;
            Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
            string text = "Screen:{0}\nWorkingArea:{1}";
            text = string.Format(text, screen.ToString(), workingArea.ToString());
            MessageBox.Show(text);
        }

        
    }
}
